package shootplane;

import java.awt.image.BufferedImage;

/**
 * 英雄机类：继承FlyObject 子弹、生命、分数
 */
public class Hero extends FlyObject {
    private int life;//英雄机生命
    private Bullet bullet;
    private int awardType;//判断奖励类型，攻击子弹类型
    private boolean check;//判断是否收到撞击，是否显示爆炸效果
    private int count;//显示爆炸效果的计数
    private int shootSpeed;//发射子弹速度

    public Hero() {
        x = 150;
        y = 450;
        // hero0.png图片和Hero类在同一个包下
        image = ShootGame.hero0Img;
        width = image.getWidth();
        height = image.getHeight();
        speed = 1;
        life = 3;
        awardType = 0;
        count = 0;
        check = false;
        shootSpeed = 30;
    }

    // 英雄机移动
    BufferedImage[] images = {ShootGame.hero0Img, ShootGame.hero1Img};
    BufferedImage[] images2 = {ShootGame.hero_ember0Img, ShootGame.hero_ember1Img, ShootGame.hero_ember2Img, ShootGame.hero_ember3Img};

    @Override
    public void move() {
        //切换image
        if (check) {
            if (count < 4) {
                image = images2[count];
                count++;
            } else {
                count = 0;
                check = false;
            }
        } else {
            image = images[speed++ % 2];
        }
    }

    //敌机撞击
    public boolean crashFlyings(FlyObject flying) {
        int x = flying.getX();
        int y = flying.getY();
        int flyingWidth = flying.getWidth();
        int flyingHeight = flying.getHeight();
        return (this.x < x + flyingWidth && x < this.x + width && this.y + height / 3 < y + flyingHeight && y < this.y + height);
    }

    //撞击子弹
    public boolean crashBulletEnemy(BulletEnemy a) {
        int x = a.getX();
        int y = a.getY();
        return this.x < x && x < this.x + width && this.y + height / 3 < y && y < this.y + height;
    }

    //发射子弹
    public Bullet[] shoot() {
        int type = 0;
        if (awardType >= 70) {
            type = 7;
        } else if (awardType >= 40) {
            type = 6;
        } else if (awardType >= 20) {
            type = 5;
        } else if (awardType >= 10) {
            type = 4;
        } else if (awardType >= 5) {
            type = 3;
        } else if (awardType >= 1) {
            type = 2;
        } else if (awardType >= 0) {
            type = 1;
        }
        Bullet[] bu;

        if (type == 1) {
            bu = new Bullet[1];
            shootSpeed = 20;
            bu[0] = new Bullet(x + width / 2 - ShootGame.bulletImg.getWidth() / 2, y);
        } else if (type == 2) {
            bu = new Bullet[2];
            shootSpeed = 20;
            bu[0] = new Bullet(x + width / 4, y);
            bu[1] = new Bullet(x + width * 3 / 4, y);
        } else if (type == 3) {
            bu = new Bullet[2];
            shootSpeed = 15;
            bu[0] = new Bullet(x + width / 4, y);
            bu[1] = new Bullet(x + width * 3 / 4, y);
        } else if (type == 4) {
            bu = new Bullet[3];
            shootSpeed = 15;
            bu[0] = new Bullet(x + width / 4, y);
            bu[1] = new Bullet(x + width / 2, y);
            bu[2] = new Bullet(x + width * 3 / 4, y);
        } else if (type == 5) {
            bu = new Bullet[4];
            shootSpeed = 10;
            bu[0] = new Bullet(x, y);
            bu[1] = new Bullet(x + width / 4, y);
            bu[2] = new Bullet(x + width * 3 / 4, y);
            bu[3] = new Bullet(x + width, y);
        } else if (type == 6) {
            bu = new Bullet[6];
            shootSpeed = 5;
            bu[0] = new Bullet(x, y);
            bu[1] = new Bullet(x + width * 2 / 10, y);
            bu[2] = new Bullet(x + width * 4 / 10, y);
            bu[3] = new Bullet(x + width * 6 / 10, y);
            bu[4] = new Bullet(x + width * 8 / 10, y);
            bu[5] = new Bullet(x + width, y);
        } else if (type == 7) {
            bu = new Bullet[8];
            shootSpeed = 5;
            bu[0] = new Bullet(x - width * 2 / 10, y);
            bu[1] = new Bullet(x, y);
            bu[2] = new Bullet(x + width * 2 / 10, y);
            bu[3] = new Bullet(x + width * 4 / 10, y);
            bu[4] = new Bullet(x + width * 6 / 10, y);
            bu[5] = new Bullet(x + width * 8 / 10, y);
            bu[6] = new Bullet(x + width, y);
            bu[7] = new Bullet(x + width * 12 / 10, y);
//            for(int i=0;i<35;i++){
//                bu[i] = new Bullet(10*(i+1), y);
//            }
        } else {
            bu = new Bullet[1];
            shootSpeed = 15;
            bu[0] = new Bullet(x + width / 2 - ShootGame.bulletImg.getWidth() / 2, y);
        }
        return bu;
    }

    public int getShootSpeed() {
        return shootSpeed;
    }

    public void setShootSpeed(int shootSpeed) {
        this.shootSpeed = shootSpeed;
    }

    public boolean isCheck() {
        return check;
    }

    public void setCheck(boolean check) {
        this.check = check;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getAwardType() {
        return awardType;
    }

    public void setAwardType(int awardType) {
        this.awardType = awardType;
    }

    public int getLife() {
        return life;
    }

    public void setLife(int life) {
        this.life = life;
    }
}
